\section{Camlp4 SourceCode Exploration}
Users are recommended to read a html version of camlp4 documentation
built from \textit{camlp4} source tree:
\href{http://www.seas.upenn.edu/~hongboz/hongbo_zhang_files/camlp4/}{camlp4 API}











\subsection{Camlp4.Register}
It provides a functor mechanism for modularity.
\textit{Camlp4.PreCast.AstFilters} provides a
\textit{Camlp4.Sig.AstFilters} implementation. Here
\textit{Camlp4.Register.AstFilter} provides a functor mechanism
to do some side effect.

\begin{ocamlcode}
module AstFilter
  (Id : Sig.Id) (Maker : functor (F : Sig.AstFilters) -> sig end) =
struct
  declare_dyn_module Id.name (fun _ -> let module M = Maker AstFilters in ());
\end{ocamlcode}

\inputminted[fontsize=\scriptsize,]{ocaml}{code/camlp4/source/AstFilters.ml}
\captionof{listing}{AstFilters \label{lst:AstFilters}}



\begin{ocamlcode}
(** file Camlp4Ast.mlast   in the file we have *)
Camlp4.Struct.Camlp4Ast.Make : Loc -> Sig.Camlp4Syntax
  module Ast = struct
     include Sig.MakeCamlp4Ast Loc 
  end ;
\end{ocamlcode}
\captionof{listing}{Camlp4Ast Make\label{lst:Camlp4Ast Make}}


\subsection{Camlp4.Struct.mlpack}
\label{Camlp4.Struct}
It packs some modules in \textit{Struct} directory
Struct is the main meat for \textit{camlp4}

\begin{bashcode}
AstFilters
Camlp4Ast
Camlp4Ast2OCamlAst
CleanAst
CommentFilter
DynLoader
EmptyError
EmptyPrinter
FreeVars
Lexer
Loc
Quotation
Token
Grammar
DynAst
\end{bashcode}


\subsection{Camlp4.PreCast}

As said above, the main meat was implemented in
\textit{Struct}(\ref{Camlp4.Struct}) directory,

\begin{ocamlcode}
  module Loc = Struct.Loc;
  module Ast = Struct.Camlp4Ast.Make Loc;
  module Token = Struct.Token.Make Loc;
  module Lexer = Struct.Lexer.Make Token;
  module Gram = Struct.Grammar.Static.Make Lexer;
  module DynLoader = Struct.DynLoader;
  module Quotation = Struct.Quotation.Make Ast;
  module MakeSyntax (U:sig end) =
    OCamlInitSyntax.Make Ast Gram Quotation;
  module Syntax = MakeSyntax (struct end)
  module AstFilters = Struct.AstFilters.Make Ast;
  module MakeGram = Struct.Grammar.Static.Make;
  module Printers = struct
    module OCaml = Printers.OCaml.Make Syntax;
    module OCamlr = Printers.OCamlr.Make Syntax;
    (* module OCamlrr = Printers.OCamlrr.Make Syntax; *)
    module DumpOCamlAst = Printers.DumpOCamlAst.Make Syntax;
    module DumpCamlp4Ast = Printers.DumpCamlp4Ast.Make Syntax;
    module Null = Printers.Null.Make Syntax;
  end;
\end{ocamlcode}

As you can see, you can make the whole syntax at your will.

\subsection{Camlp4.Struct.AstFilters}
\label{Camlp4.Struct.AstFilters}

\todo{I don't know where to dispath AstFilters yet}

\subsection{Camlp4.Struct.Camlp4Ast2OCamlAst}
\label{Camlp4.Struct.Camlp4Ast2OCamlAst}

This file shows how to translate \textit{Camlp4As} to
\textit{OCamlAst}


\begin{ocamlcode}
# module X = Camlp4.Struct.Camlp4Ast2OCamlAst.Make Ast;  
module X :
  sig
    value sig_item :
      Camlp4.PreCast.Ast.sig_item ->
      Camlp4_import.Parsetree.signature;
    value str_item :
      Camlp4.PreCast.Ast.str_item ->
      Camlp4_import.Parsetree.structure;
    value phrase :
      Camlp4.PreCast.Ast.str_item ->
      Camlp4_import.Parsetree.toplevel_phrase;
   end
# X.str_item <:str_item< value x = 3 ;>>;
X.str_item <:str_item< value x = 3 ;>>;
- : Camlp4_import.Parsetree.structure =
[{pstr_desc=
   Pstr_value Camlp4_import.Asttypes.Nonrecursive
    [({ppat_desc=Ppat_var "x"; ppat_loc=},
     {pexp_desc=Pexp_constant (Camlp4_import.Asttypes.Const_int 3);
      pexp_loc=})];
  pstr_loc=}]
# <:str_item< value x = 3 ; >>;
<:str_item< value x = 3 ; >>;
- : Camlp4.PreCast.Ast.str_item =
StSem  (StVal  ReNil (BiEq  (PaId  (IdLid  "x")) (ExInt  "3"))) (StNil)
\end{ocamlcode}


\begin{ocamlcode}
s2s <:str_item< $exp: (Ast.ExTup _loc (Ast.ExInt _loc "a")) $ >> ;
Exception: Loc.Exc_located  (Failure "singleton tuple").
\end{ocamlcode}

\begin{ocamlcode}
s2s <:str_item< $exp: ( (Ast.ExInt _loc "a")) $ >> ;
s2s <:str_item< $exp: ( (Ast.ExInt _loc "a")) $ >> ;
Exception:
Loc.Exc_located 
 (Failure
   "Integer literal exceeds the range of representable integers of type int").  
\end{ocamlcode}
   
 
\textit{Camlp4\_import} imports type definitions of \textit{ocaml}
Parsetree and then dump to it.

Something interesting here is that for quotations, the last semi is
not necessary, when you add a trailing \textit{;}, you add a trailing
\textit{StNil} here, it's fine when you generate syntax tree, but it's
\textit{a problem when you do pattern match}.  This is also true for
other syntax construct.  \textit{Don't add a trailing ;} when do
pattern match.

\subsection{Camlp4.Struct.CleanAst}
\label{Camlp4.Struct.CleanAst}
This module is supposed to do \textit{StNil,ExNil} elemination.

\begin{ocamlcode}
    method str_item st =
      match super#str_item st with
      [ <:str_item< $ <:str_item<>> $; $st$ >> |
        <:str_item< $st$; $ <:str_item<>> $ >> -> st
      | <:str_item@loc< type $ <:ctyp<>> $ >> -> <:str_item@loc<>>
      | <:str_item@loc< value $rec:_$ $ <:binding<>> $ >> -> <:str_item@loc<>>
      | st -> st ];
\end{ocamlcode}

\subsection{Camlp4.Struct.CommentFilter}
\label{Camlp4.Struct.CommentFilter}

It was used in \textit{Printers}.

\begin{ocamlcode}
./Printers/OCaml.ml:65:  module CommentFilter = Struct.CommentFilter.Make Token;
./Printers/OCaml.ml:66:  value comment_filter = CommentFilter.mk ();
\end{ocamlcode}

\subsection{Camlp4.Struct.DynAst}
\label{Camlp4.Struct.DynAst}

Support Quotation mechanism.

\begin{ocamlcode}
  type dyn;
  external dyn_tag : tag 'a -> tag dyn = "%identity";

  module Pack(X : sig type t 'a; end) = struct
    (* These Obj.* hacks should be avoided with GADTs *)
    type pack = (tag dyn * Obj.t);
    exception Pack_error;
    value pack tag v = (dyn_tag tag, Obj.repr v);
    value unpack (tag : tag 'a) (tag', obj) =
      if dyn_tag tag = tag' then (Obj.obj obj : X.t 'a) else raise Pack_error;
    value print_tag f (tag, _) = Format.pp_print_string f (string_of_tag tag);
  end;
  
\end{ocamlcode}
\captionof{listing}{Packing Ast}

\subsection{Camlp4.Struct.DynLoader}
\label{Camlp4.Struct.DynLoader}

\subsection{Camlp4.Struct.EmptyError}
\label{Camlp4.Struct.EmptyError}

\subsection{Camlp4.Struct.FreeVars}
\label{Camlp4.Struct.FreeVars}

\begin{ocamlcode}
module X = Camlp4.Struct.FreeVars.Make Ast;  
X.S.iter (fun x -> do
      {print_string x;
           print_newline ()}) (X.free_vars X.S.empty <:expr< let f x = x  + y  in f 3 >> );
+
y
\end{ocamlcode}

This is buggy, since when you open a module, you will be
screwed. Actually, you can not know whether a variable is free or not
at the syntax phase, the result got above demonstrates that you can
not know \textit{+} is in the environment or not. It's a hack.

\subsection{Camlp4.Struct.Lexer.mll}
\label{Camlp4.Struct.Lexer.mll}
It was based on \textit{ocamllex}. One interesting bit is delimitors.

\begin{ocamlcode}
  (* These chars that can't start an expression or a pattern: *)
  let safe_delimchars = ['%' '&' '/' '@' '^']

  (* These symbols are unsafe since "[<", "[|", etc. exsist. *)
  let delimchars = safe_delimchars | ['|' '<' '>' ':' '=' '.']

  let left_delims  = ['(' '[' '{']
  let right_delims = [')' ']' '}']

  let left_delimitor =
    (* At least a safe_delimchars *)
    left_delims delimchars* safe_delimchars (delimchars|left_delims)*

  (* A '(' or a new super '(' without "(<" *)
  | '(' (['|' ':'] delimchars*)?
  (* Old brackets, no new brackets starting with "[|" or "[:" *)
  | '[' ['|' ':']?
  (* Old "[<","{<" and new ones *)
  | ['[' '{'] delimchars* '<'
  (* Old brace and new ones *)
  | '{' (['|' ':'] delimchars*)?

  let right_delimitor =
    (* At least a safe_delimchars *)
    (delimchars|right_delims)* safe_delimchars (delimchars|right_delims)* right_delims
  (* A ')' or a new super ')' without ">)" *)
  | (delimchars* ['|' ':'])? ')'
  (* Old brackets, no new brackets ending with "|]" or ":]" *)
  | ['|' ':']? ']'
  (* Old ">]",">}" and new ones *)
  | '>' delimchars* [']' '}']
  (* Old brace and new ones *)
  | (delimchars* ['|' ':'])? '}'
  
\end{ocamlcode}
\captionof{listing}{Camlp4 Lexer Delimitors}

Some lexing rules as follows:

\begin{ocamlcode}
    | '"'
        { with_curr_loc string c;
          let s = buff_contents c in STRING (TokenEval.string s, s)             }
    | "'" (newline as x) "'"
        { update_loc c None 1 false 1; CHAR (TokenEval.char x, x)               }
    | "'" ( [^ '\\' '\010' '\013']
          | '\\' (['\\' '"' 'n' 't' 'b' 'r' ' ' '\'']
                |['0'-'9'] ['0'-'9'] ['0'-'9']
                |'x' hexa_char hexa_char)
          as x) "'"                                { CHAR (TokenEval.char x, x) }
  
\end{ocamlcode}

        
\subsection{Camlp4.Struct.Loc}
\label{Camlp4.Struct.Loc}


\subsection{Camlp4.Struct.Token}
\label{Camlp4.Struct.Token}

\begin{ocamlcode}
module Make (Loc : Sig.Loc) : Sig.Camlp4Token with module Loc = Loc;

module Eval : sig
  value char : string -> char;
      (** Convert a char token, where the escape sequences (backslashes)
          remain to be interpreted; raise [Failure] if an
          incorrect backslash sequence is found; [Token.Eval.char (Char.escaped c)]
          returns [c] *)

  value string : ?strict:unit -> string -> string;
      (** [Taken.Eval.string strict s]
          Convert a string token, where the escape sequences (backslashes)
          remain to be interpreted; raise [Failure] if [strict] and an
          incorrect backslash sequence is found;
          [Token.Eval.string strict (String.escaped s)] returns [s] *)
end;
\end{ocamlcode}

\subsection{Camlp4.Struct.Quotation}
\label{Camlp4.Struct.Quotation}

\begin{ocamlcode}
  value expand_quotation loc expander pos_tag quot =
    debug quot "expand_quotation: name: %s, str: %S@." quot.q_name quot.q_contents in
    let loc_name_opt = if quot.q_loc = "" then None else Some quot.q_loc in
    try expander loc loc_name_opt quot.q_contents with
    [ Loc.Exc_located _ (Error.E _) as exc ->
        raise exc
    | Loc.Exc_located iloc exc ->
        let exc1 = Error.E (quot.q_name, pos_tag, Expanding, exc) in
        raise (Loc.Exc_located iloc exc1)
    | exc ->
        let exc1 = Error.E (quot.q_name, pos_tag, Expanding, exc) in
        raise (Loc.Exc_located loc exc1) ];

  value expand loc quotation tag =
    let pos_tag = DynAst.string_of_tag tag in
    let name = quotation.q_name in
    debug quot "handle_quotation: name: %s, str: %S@." name quotation.q_contents in
    let expander =
      try find name tag
      with
      [ Loc.Exc_located _ (Error.E _) as exc -> raise exc
      | Loc.Exc_located qloc exc ->
          raise (Loc.Exc_located qloc (Error.E (name, pos_tag, Finding, exc)))
      | exc ->
          raise (Loc.Exc_located loc (Error.E (name, pos_tag, Finding, exc))) ]
    in
    let loc = Loc.join (Loc.move `start quotation.q_shift loc) in
    expand_quotation loc expander pos_tag quotation;
  \end{ocamlcode}
  \captionof{listing}{Quotation mechanism}

  Here quotation introduces \textit{Obj.magic} hacks since you need a
  function like

  \begin{ocamlcode}
    Loc.t -> (Loc.t -> string option -> string -> 'c) ->
    string -> Camlp4.Sig.quotation -> 'c
  \end{ocamlcode}

  All the parsers are stored in \textit{expander\_table}, so you need
  pack their types here. 

\subsection{Camlp4.Struct.Grammar.mllpack}
\label{Camlp4.Struct.Grammar}

\begin{bashcode}
Delete
Dynamic
Entry
Failed
Find
Fold
Insert
Parser
Print
Search
Static
Structure
Tools
\end{bashcode}

Grammar is directory with a \textit{.mlpack} in \textit{Struct}
directory to pack all the modules in \textit{Grammar}. In this
directory, it mainly defines the syntax level engine.  First let's
take a look at \textit{Camlp4.Sig.Grammar}.  It has type definitions
for \textit{assoc, position}, and four module types: \textit{Action,
  Structure, Dynamic,Static}.

For external use, it's exported in \textit{Camlp4.PreCast}

\begin{ocamlcode}
  module Gram = Camlp4.Struct.Grammar.Static.Make Lexer;
\end{ocamlcode}

\subsubsection{Camlp4.Struct.Grammar.Structure}
\label{Camlp4.Struct.Grammar.Structure}

In file \textit{Camlp4.Struct.Grammar.Structure}, it defines a
\textit{module type S}, which includes \textit{type gram,
  token\_info,} \textit{token\_stream,internal\_entry},
\textit{desc,level and symbol, }, Then it defines a functor
\textit{Make} which is given a \textit{Lexer} and implements
\textit{module type S}. There are some interesting types here

\begin{ocamlcode}
  type gram =
    { gfilter         : Token.Filter.t;
      gkeywords       : Hashtbl.t string (ref int);
      glexer          : Loc.t -> Stream.t char -> Stream.t (Token.t * Loc.t);
      warning_verbose : ref bool;
      error_verbose   : ref bool };
\end{ocamlcode}

\subsubsection{Camlp4.Struct.Grammar.Delete}
\label{Camlp4.Struct.Grammar.Delete}

Deleting a rule



\subsubsection{Camlp4.Struct.Grammar.Print}
\label{Camlp4.Struct.Grammar.Print}
This file only depends \textit{Structure.S} It implements a lot of
interesting stuff for debugging the dynamic parser. It's used by
\textit{module Entry}

\begin{ocamlcode}
./Entry.ml:21:  module Dump  = Print.MakeDump Structure;
./Entry.ml:22:  module Print = Print.Make Structure;
\end{ocamlcode}

\subsubsection{Camlp4.Struct.Grammar.Tools}
Defines some utilities. (really miss generic programming here)

\subsubsection{Camlp4.Struct.Grammar.Parser}
\label{Camlp4.Struct.Grammar.Parser}
Parser engine 

\subsubsection{Camlp4.Struct.Grammar.Entry}
\label{Camlp4.Struct.Grammar.Entry}
Entry's API is relatively simple, it re-exports the API in
module \textit{Print} and \textit{Dump}.


\subsubsection{Camlp4.Struct.Grammar.Failed}
\label{Camlp4.Struct.Grammar.Failed}

\subsubsection{Camlp4.Struct.Grammar.Find}
\label{Camlp4.Struct.Grammar.Find}
Deprecated

\subsubsection{Camlp4.Struct.Grammar.Search}
\label{Camlp4.Struct.Grammar.Search}


\subsubsection{Camlp4.Struct.Grammar.Fold}
\label{Camlp4.Struct.Grammar.Fold}

\subsubsection{Camlp4.Struct.Grammar.Insert}
\label{Camlp4.Struct.Grammar.Insert}

\subsubsection{Camlp4.Struct.Grammar.Tools}
\label{Camlp4.Struct.Grammar.Tools}


\subsubsection{Camlp4.Struct.Grammar.Dynamic}
\label{Camlp4.Struct.Grammar.Dynamic}
They export another interface compared with
\textit{Camlp4.Struct.Grammar.Dynamic}: \textit{Sig.Grammar.Dynamic}

\subsubsection{Camlp4.Struct.Grammar.Static}
\label{Camlp4.Struct.Grammar.Static}
This file exports most API discussed before, and was finally exported
by \textit{PreCast}. It's interesting to read it line by line. Notice
the API in \textit{PreCast} is limited by its signature file, so you
need to use \textit{Camlp4.Struct.Grammar.Static.Make} for the full
power, also you can customize your \textit{Lexer} here.

\begin{ocamlcode}
module Sig = Camlp4.Sig; (** hack by hongboz *)
value uncurry f (x,y) = f x y;
value flip f x y = f y x;

module Make (Lexer : Sig.Lexer)
: Sig.Grammar.Static with module Loc = Lexer.Loc
                        and module Token = Lexer.Token
= struct
  module Structure = Structure.Make Lexer;
  module Delete = Delete.Make Structure;
  module Insert = Insert.Make Structure;
  module Fold = Fold.Make Structure;
  module Tools = Tools.Make Structure;
  include Structure;

  value gram =
    let gkeywords = Hashtbl.create 301 in
    {
      gkeywords = gkeywords;
      gfilter = Token.Filter.mk (Hashtbl.mem gkeywords);
      glexer = Lexer.mk ();
      warning_verbose = ref True; (* FIXME *)
      error_verbose = Camlp4_config.verbose
    };

  module Entry = struct
    module E = Entry.Make Structure;
    type t 'a = E.t 'a;
    value mk = E.mk gram;
    value of_parser name strm = E.of_parser gram name strm;
    value setup_parser = E.setup_parser;
    value name = E.name;
    value print = E.print;
    value clear = E.clear;
    value dump = E.dump;
    value obj x = x;
  end;

  value get_filter () = gram.gfilter;

  value lex loc cs = gram.glexer loc cs;

  value lex_string loc str = lex loc (Stream.of_string str);

  value filter ts = Tools.keep_prev_loc (Token.Filter.filter gram.gfilter ts);

  value parse_tokens_after_filter entry ts = Entry.E.parse_tokens_after_filter entry ts;

  value parse_tokens_before_filter entry ts = parse_tokens_after_filter entry (filter ts);

  value parse entry loc cs = parse_tokens_before_filter entry (lex loc cs);

  value parse_string entry loc str = parse_tokens_before_filter entry (lex_string loc str);

  value delete_rule = Delete.delete_rule;

  value srules e rl =
    Stree (List.fold_left (flip (uncurry (Insert.insert_tree e))) DeadEnd rl);
  value sfold0 = Fold.sfold0;
  value sfold1 = Fold.sfold1;
  value sfold0sep = Fold.sfold0sep;
  (* value sfold1sep = Fold.sfold1sep; *)
  value extend = Insert.extend;
end;
\end{ocamlcode}
\captionof{listing}{Camlp4.Struct.Grammar.Static}

\subsection{Camlp4.Register}
Let's see what's in \verb|Register| Listing \ref{lst:Camlp4
  Register}module


\inputminted[fontsize=\scriptsize,
]{ocaml}{code/camlp4/source/Register.ml}
\captionof{listing}{Camlp4 Register\label{lst:Camlp4 Register}}

Notice that functors Plugin, SyntaxExtension, OCamlSyntaxExtension,
OCamlSyntaxExtension, SyntaxPlugin, they did the same thing
essentially, they apply the second Funtor to
Syntax(Camlp4.PreCast.Syntax).

Functors Printer, OCamlPrinter, OCamlPrinter, they did the same thing,
apply the Make to Syntax, then register it. 

Functors Parser, OCamlParser, did the same thing. 

Functors AstFilter  did nothing interesting.

It sticks to the toplevel Listing

\inputminted[fontsize=\scriptsize, firstline=123, lastline=126,
]{ocaml}{code/camp4/source/Register.ml}
\captionof{listing}{Camlp4 Register Part 2 \label{lst:Camlp4 Register
    Part 2}}

It mainly hook some global variables, like
\verb|Camlp4.Register.loaded_modlules|, but there's no fresh meat in
this file.  To conclude, Register did nothing, except making your code
more modular, or register your syntax extension.

As we said, another utility, you can inspect what modules you have
loaded in toplevel:

\begin{ocamlcode}
Camlp4.Register.loaded_modules;;
- : string list ref =
{Pervasives.contents =
  ["Camlp4GrammarParser"; "Camlp4OCamlParserParser";
   "Camlp4OCamlRevisedParserParser"; "Camlp4OCamlParser";
   "Camlp4OCamlRevisedParser"]}
\end{ocamlcode}

\subsection{Camlp4.Printers.mlpack}
\label{Camlp4.Printers}

Now the last step is to get a pretty printer for the ast.

\begin{bashcode}
DumpCamlp4Ast
DumpOCamlAst
Null
OCaml
OCamlr
\end{bashcode}

\subsection{Camlp4.Printers.DumpOCamlAst}
\label{Camlp4.Printers.DumpOCamlAst}
It mainly make use of the module
\textit{Camlp4.Struct.Camlp4Ast2OCamlAst.}(\ref{Camlp4.Struct.Camlp4Ast2OCamlAst})
to get a binary dump, and pass it to ocaml compiler.

\subsection{Camlp4.Printers.DumpCamlp4Ast}
\label{Camlp4.Printers.DumpCamlp4Ast}
It mainly dump camlp4Ast directly using \textit{output\_value}.

\subsection{Camlp4.Printers.OCaml}
\label{Camlp4.Printers.OCaml}
A full blown ocaml original syntax printer.

\subsection{Camlp4.Printers.OCamlr}
\label{Camlp4.Printers.OCamlr}
A full blown ocaml revised syntax printer.

\subsection{Camlp4.Printers.Null}
\label{Camlp4.Printers.Null}

\subsection{Camlp4Parsers}
\label{Camlp4Parsers}

The source code demonstrated above is the runtime. In this directory
we begin to extend our syntax.

Take \textit{Camlp4OCamlRevisedParser} as a learning example.

\subsection{Camlp4Parsers.Camlp4OCamlRevisedParser}
\label{Camlp4Parsers.Camlp4OCamlRevisedParser}

\subsubsection{Scaffle-code}
First you need to functorize your code

\begin{ocamlcode}
module Id = struct
  value name = "Camlp4OCamlRevisedParser";
  value version = Sys.ocaml_version;
end;

module Make (Syntax : Sig.Camlp4Syntax) = struct
  open Sig;
  include Syntax;
  ...
end;
let module M = Register.OCamlSyntaxExtension Id Make in ();  
\end{ocamlcode}
\captionof{listing}{Syntax Extension Framework}

You can also add some options

\begin{ocamlcode}
  value help_sequences () =
    do {
      Printf.eprintf "\
New syntax:\
\n    (e1; e2; ... ; en) OR begin e1; e2; ... ; en end\
\n    while e do e1; e2; ... ; en done\
\n    for v = v1 to/downto v2 do e1; e2; ... ; en done\
\nOld syntax (still supported):\
\n    do {e1; e2; ... ; en}\
\n    while e do {e1; e2; ... ; en}\
\n    for v = v1 to/downto v2 do {e1; e2; ... ; en}\
\nVery old (no more supported) syntax:\
\n    do e1; e2; ... ; en-1; return en\
\n    while e do e1; e2; ... ; en; done\
\n    for v = v1 to/downto v2 do e1; e2; ... ; en; done\
\n";
      flush stderr;
      exit 1
    }
  ;
  Options.add "-help_seq" (Arg.Unit help_sequences)
    "Print explanations about new sequences and exit.";
\end{ocamlcode}
\captionof{listing}{Camlp4 Option support}

After that, you may or not clean all your entries before. Then you
begin to extend your syntax with some utilities. Those utilities are
quite non-necessary, but I guess the main purpose here is to reduce
dependency.

\subsubsection{Utilities}
\label{Utilities}

\inputminted[fontsize=\scriptsize]{ocaml}{code/camlp4/parsers/util.ml}
\captionof{listing}{Utiliti functions in Camlp4Revised Parser}

\todo{to be finished}
\inputminted[fontsize=\scriptsize]{ocaml}{code/camlp4/parsers/revised_parsing.ml}
\captionof{listing}{Revised Syntax Grammar}

\begin{ocamlcode}
  
\end{ocamlcode}

\section{Camlp4Ast}

As the code Listing \ref{lst:Camlp4 Ast Definition} demonstrate below,
there are several categories including \textit{ident, ctyp,patt,expr,
  module\_type, sig\_item, with\_constr, binding, rec\_binding,
  module\_binding, match\_case, module\_expr,str\_item, class\_type,
  class\_sig\_item, class\_expr, class\_str\_item,}. And there are
antiquotations for each syntax category, i.e,
\textit{IdAnt,TyAnt,PaAnt,ExAnt,MtAnt, SgAnt, WcAnt, BiAnt,
  RbAnt,MbAnt,McAnt,MeAnt,StAnt,CtAnt,CgAnt, CeAnt, CrAnt}


\inputminted[fontsize=\scriptsize,
]{ocaml}{code/camlp4/ast/def.ml}
\captionof{listing}{Camlp4 Ast Definition\label{lst:Camlp4 Ast Definition}}


\section{TestFile}
\label{sec:testfile}
Some test files are pretty useful(in the distribution of camlp4)
like \verb|test/fixtures/macro_test.ml|.

